package parspack;

import java.util.HashSet;
import java.util.Set;

public class Query {
	Set<String> result = new HashSet<String>();
	public Set<String> init(String arg) {
		arg += '\n';
		Query query = new Query();
		Query.State s = query.new WhiteSpaceState();
		int i = 0;
		while (!(s instanceof EndState)) {
			s = s.eat(arg.charAt(i++));
		}
		return query.result;
	}
	class EndState implements State {
		public State eat(char c){
			return this;
		}
	}
	class WordState implements State {
		String buffer = new String();
		WordState(char s){
			buffer += s;
		}
		public State eat(char c){
			switch(c){
			case ' ':
				Query.this.result.add(this.buffer);
				return new WhiteSpaceState();
			case '\n':
				Query.this.result.add(this.buffer);
				return new EndState();
			default:
				this.buffer+=c;
				return this;
			}
		}
	}
	class WhiteSpaceState implements State {
		public State eat(char c){
			switch(c){
			case ' ':
				return this;
			case '\n':
				return new EndState();
			default:
				return new WordState(c);
			}
		}
	}
	interface State {
		State eat(char c);
	}
}

